package com.xq.chrome.web.other.conf;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;


@Configuration
public class DataSourceConfig {

  @Bean(name = "dataSource")
  @Lazy
  public DataSource dataSource(Environment env) {
    HikariConfig ds = new HikariDataSource();

    System.out.println(env.getProperty("spring.datasource.hikari.jdbc-url"));
    ds.setJdbcUrl(env.getProperty("spring.datasource.hikari.jdbc-url"));
    ds.setPassword(env.getProperty("spring.datasource.hikari.password"));
    ds.setUsername(env.getProperty("spring.datasource.hikari.username"));
    ds.setDriverClassName(env.getProperty("spring.datasource.hikari.driver-class-name"));
    ds.setMaximumPoolSize(5);
    return (DataSource) ds;
  }
}
